package com.xuan.chatroom.mapper;

import com.xuan.chatroom.model.Friend;
import com.xuan.chatroom.model.MessageSession;
import com.xuan.chatroom.model.MessageSessionUserItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;

import java.util.List;

@Mapper
public interface MessageSessionMapper {

    // 1. 根据当前登录的用户id 查询所有存在的会话id,并将会话按时间降序排序
    List<Integer> queryAllSessionIdByUserId(Integer userId);


    // 2. 根据每个会话查询当前会话关联的所有好友,除去自己
    List<Friend> queryFriendsBySessionId(Integer sessionId, Integer selfUserId);


    // 3. 往数据库中新增一个会话并返回 sessionId
    @Options(useGeneratedKeys = true, keyProperty = "sessionId")
    @Insert("insert into message_session values (null, now())")
    int addMessageSession(MessageSession messageSession);

    // 4. 往新增的会话中插入会话关联的 userId
    int addMessageSessionUser(MessageSessionUserItem messageSessionUserItem);

}
